package cn.itcast.javaobject;

/**
 * @title: OverLoad
 * @Author Zhou
 * @Date: 2022/1/4 13:53
 * @Version 1.0
 */
/**
 * 方法名必须相同
 * 形参列表：必须不同，形参类型或个数或顺序，至少有一样不同，参数名无要求
 * 返回类型无要求
 */
public class OverLoad {
    public static void main(String[] args) {
        MyCalculator mc = new MyCalculator();
        int calculate = mc.calculate(1, 2);
        System.out.println("calculate = " + calculate);
        double calculate1 = mc.calculate(2, 1.5);
        System.out.println("calculate1 = " + calculate1);
        double calculate2 = mc.calculate(10.5, 5);
        System.out.println("calculate2 = " + calculate2);
        int calculate3 = mc.calculate(1, 5, 7);
        System.out.println("calculate3 = " + calculate3);
    }
}

class MyCalculator {
    public int calculate(int n1, int n2) {
        return n1 + n2;
    }

    public double calculate(int n1, double n2) {
        return n1 + n2;
    }

    public double calculate(double n1, int n2) {
        return n1 + n2;
    }

    public int calculate(int n1, int n2, int n3) {
        return n1 + n2 + n3;
    }
}